package view;

import java.awt.Color;
import util.EventoBotoes;
import util.ViewUtil;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import model.Candidato;
import model.Cargo;
import util.UrnaUtil;

public class CadastroCandidato extends javax.swing.JDialog {

  //
  Candidato candidatoModel;
  ArrayList<Cargo> cargos = Cargo.getAllCargos();
  String endFotoCandidato;
  String endFotoVicePriSuplente;
  String endFotoSegSuplente;

  //
  public CadastroCandidato(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    setTitle("Cadastro de Candidatos");
    initComponents();
    setLocationRelativeTo(null);
    EventoBotoes.inicio(jPanelBotoes.getComponents(), jPanelStatus.getComponents());
    ViewUtil.trocaPanels(jPanelMeio, jPanelConsulta);
    carregarComboBoxCargo();
    ativaDesativaBotoes(false);
  }

  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jPanelCampos = new javax.swing.JPanel();
    jPanel1 = new javax.swing.JPanel();
    jPanel6 = new javax.swing.JPanel();
    jLabelCargo = new javax.swing.JLabel();
    jPanel12 = new javax.swing.JPanel();
    jComboBoxCargos = new javax.swing.JComboBox();
    jPanel2 = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();
    jPanel4 = new javax.swing.JPanel();
    lblFotoCandidato = new javax.swing.JLabel();
    jPanel5 = new javax.swing.JPanel();
    jLabelNomeCandidato = new javax.swing.JLabel();
    jTextFieldNomeCandidato = new javax.swing.JTextField();
    jLabelPartido = new javax.swing.JLabel();
    jTextFieldPartido = new javax.swing.JTextField();
    jLabelNumeroCandidato = new javax.swing.JLabel();
    jPanel11 = new javax.swing.JPanel();
    jTextFieldNumeroCandidato = new javax.swing.JTextField();
    btnFotoCandidato = new javax.swing.JButton();
    pnlViceSuplente = new javax.swing.JPanel();
    pnlVicePriSuplente = new javax.swing.JPanel();
    pnlNomeVicePriSuplente = new javax.swing.JPanel();
    jPanel16 = new javax.swing.JPanel();
    lblTextoVicePriSuplente = new javax.swing.JLabel();
    jPanel17 = new javax.swing.JPanel();
    edtNomeVicePriSuplente = new javax.swing.JTextField();
    jPanel19 = new javax.swing.JPanel();
    btnFotoVice = new javax.swing.JButton();
    jPanel18 = new javax.swing.JPanel();
    pnlFotoVicePriSuplente = new javax.swing.JPanel();
    lblFotoVicePriSuplente = new javax.swing.JLabel();
    pnlSegSuplente = new javax.swing.JPanel();
    jPanel9 = new javax.swing.JPanel();
    jPanel13 = new javax.swing.JPanel();
    lblTextoSegSuplente = new javax.swing.JLabel();
    jPanel14 = new javax.swing.JPanel();
    edtNomeSegSuplente = new javax.swing.JTextField();
    jPanel20 = new javax.swing.JPanel();
    btnFotoSegSuplente = new javax.swing.JButton();
    jPanel15 = new javax.swing.JPanel();
    jPanel10 = new javax.swing.JPanel();
    lblFotoSegSuplente = new javax.swing.JLabel();
    jPanel7 = new javax.swing.JPanel();
    jPanel8 = new javax.swing.JPanel();
    jPanelConsulta = new javax.swing.JPanel();
    jLabelFiltro = new javax.swing.JLabel();
    jComboBoxListaFiltro = new javax.swing.JComboBox();
    jLabelValorPesquisa = new javax.swing.JLabel();
    jTextFieldInformacaoPesquisa = new javax.swing.JTextField();
    jFileChooser = new javax.swing.JFileChooser();
    jPanelBotoes = new javax.swing.JPanel();
    jButtonConsultar = new javax.swing.JButton();
    jButtonNovo = new javax.swing.JButton();
    jButtonEditar = new javax.swing.JButton();
    jButtonExcluir = new javax.swing.JButton();
    jButtonGravar = new javax.swing.JButton();
    jButtonCancelar = new javax.swing.JButton();
    jPanelMeio = new javax.swing.JPanel();
    jPanelStatus = new javax.swing.JPanel();
    jLabelStatus = new javax.swing.JLabel();
    jLabelGravacao = new javax.swing.JLabel();

    jPanelCampos.setBackground(new java.awt.Color(0, 51, 51));
    jPanelCampos.setMaximumSize(new java.awt.Dimension(800, 410));
    jPanelCampos.setMinimumSize(new java.awt.Dimension(800, 410));
    jPanelCampos.setPreferredSize(new java.awt.Dimension(800, 410));
    jPanelCampos.setLayout(new java.awt.BorderLayout());

    jPanel1.setBackground(new java.awt.Color(0, 51, 51));
    jPanel1.setMaximumSize(new java.awt.Dimension(800, 50));
    jPanel1.setMinimumSize(new java.awt.Dimension(800, 50));
    jPanel1.setPreferredSize(new java.awt.Dimension(800, 50));
    jPanel1.setLayout(new java.awt.GridLayout(2, 0));

    jPanel6.setBackground(new java.awt.Color(0, 51, 51));

    jLabelCargo.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jLabelCargo.setForeground(new java.awt.Color(255, 255, 255));
    jLabelCargo.setText("Cargo");

    javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
    jPanel6.setLayout(jPanel6Layout);
    jPanel6Layout.setHorizontalGroup(
      jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel6Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabelCargo, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(692, Short.MAX_VALUE))
    );
    jPanel6Layout.setVerticalGroup(
      jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jLabelCargo)
    );

    jPanel1.add(jPanel6);

    jPanel12.setBackground(new java.awt.Color(0, 51, 51));

    jComboBoxCargos.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
    jComboBoxCargos.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jComboBoxCargosActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
    jPanel12.setLayout(jPanel12Layout);
    jPanel12Layout.setHorizontalGroup(
      jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel12Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jComboBoxCargos, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(615, Short.MAX_VALUE))
    );
    jPanel12Layout.setVerticalGroup(
      jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jComboBoxCargos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    );

    jPanel1.add(jPanel12);

    jPanelCampos.add(jPanel1, java.awt.BorderLayout.NORTH);
    jPanel1.getAccessibleContext().setAccessibleName("");

    jPanel2.setBackground(new java.awt.Color(0, 51, 51));
    jPanel2.setMaximumSize(new java.awt.Dimension(800, 350));
    jPanel2.setMinimumSize(new java.awt.Dimension(800, 350));
    jPanel2.setPreferredSize(new java.awt.Dimension(800, 350));
    jPanel2.setLayout(new java.awt.GridLayout(2, 0, 0, 5));

    jPanel3.setBackground(new java.awt.Color(0, 51, 51));
    jPanel3.setMaximumSize(new java.awt.Dimension(800, 150));
    jPanel3.setMinimumSize(new java.awt.Dimension(800, 150));
    jPanel3.setPreferredSize(new java.awt.Dimension(800, 150));
    jPanel3.setLayout(new java.awt.BorderLayout());

    jPanel4.setBackground(new java.awt.Color(0, 51, 51));
    jPanel4.setMaximumSize(new java.awt.Dimension(150, 150));
    jPanel4.setMinimumSize(new java.awt.Dimension(150, 150));
    jPanel4.setPreferredSize(new java.awt.Dimension(150, 150));
    jPanel4.setLayout(new java.awt.CardLayout(10, 10));

    lblFotoCandidato.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/img00.jpg"))); // NOI18N
    lblFotoCandidato.setAutoscrolls(true);
    lblFotoCandidato.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
    jPanel4.add(lblFotoCandidato, "card2");

    jPanel3.add(jPanel4, java.awt.BorderLayout.EAST);

    jPanel5.setBackground(new java.awt.Color(0, 51, 51));
    jPanel5.setMaximumSize(new java.awt.Dimension(800, 150));
    jPanel5.setMinimumSize(new java.awt.Dimension(800, 150));
    jPanel5.setPreferredSize(new java.awt.Dimension(800, 150));
    jPanel5.setLayout(new java.awt.GridLayout(6, 0, 0, 2));

    jLabelNomeCandidato.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jLabelNomeCandidato.setForeground(new java.awt.Color(255, 255, 255));
    jLabelNomeCandidato.setText("Nome do Candidato");
    jLabelNomeCandidato.setMaximumSize(new java.awt.Dimension(25, 25));
    jLabelNomeCandidato.setMinimumSize(new java.awt.Dimension(25, 25));
    jLabelNomeCandidato.setPreferredSize(new java.awt.Dimension(25, 25));
    jLabelNomeCandidato.setVerifyInputWhenFocusTarget(false);
    jPanel5.add(jLabelNomeCandidato);

    jTextFieldNomeCandidato.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jTextFieldNomeCandidato.setBorder(null);
    jTextFieldNomeCandidato.setMaximumSize(new java.awt.Dimension(25, 25));
    jTextFieldNomeCandidato.setMinimumSize(new java.awt.Dimension(25, 25));
    jTextFieldNomeCandidato.setName(""); // NOI18N
    jTextFieldNomeCandidato.setPreferredSize(new java.awt.Dimension(25, 25));
    jPanel5.add(jTextFieldNomeCandidato);

    jLabelPartido.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jLabelPartido.setForeground(new java.awt.Color(255, 255, 255));
    jLabelPartido.setText("Partido");
    jLabelPartido.setMaximumSize(new java.awt.Dimension(25, 25));
    jLabelPartido.setMinimumSize(new java.awt.Dimension(25, 25));
    jLabelPartido.setPreferredSize(new java.awt.Dimension(25, 25));
    jPanel5.add(jLabelPartido);

    jTextFieldPartido.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jTextFieldPartido.setBorder(null);
    jTextFieldPartido.setMaximumSize(new java.awt.Dimension(25, 25));
    jTextFieldPartido.setMinimumSize(new java.awt.Dimension(25, 25));
    jTextFieldPartido.setPreferredSize(new java.awt.Dimension(25, 25));
    jPanel5.add(jTextFieldPartido);

    jLabelNumeroCandidato.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jLabelNumeroCandidato.setForeground(new java.awt.Color(255, 255, 255));
    jLabelNumeroCandidato.setText("Número do Candidato");
    jLabelNumeroCandidato.setMaximumSize(new java.awt.Dimension(25, 25));
    jLabelNumeroCandidato.setMinimumSize(new java.awt.Dimension(25, 25));
    jLabelNumeroCandidato.setPreferredSize(new java.awt.Dimension(25, 25));
    jLabelNumeroCandidato.setVerifyInputWhenFocusTarget(false);
    jPanel5.add(jLabelNumeroCandidato);

    jPanel11.setBackground(new java.awt.Color(0, 51, 51));
    jPanel11.setMaximumSize(new java.awt.Dimension(25, 25));
    jPanel11.setMinimumSize(new java.awt.Dimension(25, 25));
    jPanel11.setPreferredSize(new java.awt.Dimension(25, 25));
    jPanel11.setLayout(new java.awt.GridLayout(1, 2, 350, 0));

    jTextFieldNumeroCandidato.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jTextFieldNumeroCandidato.setBorder(null);
    jTextFieldNumeroCandidato.setMaximumSize(new java.awt.Dimension(25, 25));
    jTextFieldNumeroCandidato.setMinimumSize(new java.awt.Dimension(25, 25));
    jTextFieldNumeroCandidato.setPreferredSize(new java.awt.Dimension(25, 25));
    jPanel11.add(jTextFieldNumeroCandidato);

    btnFotoCandidato.setBackground(new java.awt.Color(0, 153, 204));
    btnFotoCandidato.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
    btnFotoCandidato.setForeground(new java.awt.Color(255, 255, 255));
    btnFotoCandidato.setText("Carregar Foto");
    btnFotoCandidato.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    btnFotoCandidato.setPreferredSize(new java.awt.Dimension(110, 30));
    btnFotoCandidato.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnFotoCandidatoActionPerformed(evt);
      }
    });
    jPanel11.add(btnFotoCandidato);

    jPanel5.add(jPanel11);

    jPanel3.add(jPanel5, java.awt.BorderLayout.CENTER);

    jPanel2.add(jPanel3);

    pnlViceSuplente.setBackground(new java.awt.Color(0, 51, 51));
    pnlViceSuplente.setMaximumSize(new java.awt.Dimension(800, 200));
    pnlViceSuplente.setMinimumSize(new java.awt.Dimension(800, 200));
    pnlViceSuplente.setPreferredSize(new java.awt.Dimension(800, 200));
    pnlViceSuplente.setRequestFocusEnabled(false);
    pnlViceSuplente.setLayout(new java.awt.GridLayout(2, 0, 0, 5));

    pnlVicePriSuplente.setLayout(new java.awt.BorderLayout());

    pnlNomeVicePriSuplente.setBackground(new java.awt.Color(0, 51, 51));
    pnlNomeVicePriSuplente.setMinimumSize(new java.awt.Dimension(500, 100));
    pnlNomeVicePriSuplente.setPreferredSize(new java.awt.Dimension(500, 100));
    pnlNomeVicePriSuplente.setLayout(new java.awt.GridLayout(3, 0));

    jPanel16.setBackground(new java.awt.Color(0, 51, 51));
    jPanel16.setMaximumSize(new java.awt.Dimension(400, 30));
    jPanel16.setMinimumSize(new java.awt.Dimension(400, 30));
    jPanel16.setPreferredSize(new java.awt.Dimension(400, 30));
    jPanel16.setLayout(new java.awt.CardLayout());

    lblTextoVicePriSuplente.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    lblTextoVicePriSuplente.setForeground(new java.awt.Color(255, 255, 255));
    lblTextoVicePriSuplente.setText("lblTextoVicePriSuplente");
    jPanel16.add(lblTextoVicePriSuplente, "card2");

    pnlNomeVicePriSuplente.add(jPanel16);

    jPanel17.setBackground(new java.awt.Color(0, 51, 51));
    jPanel17.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

    edtNomeVicePriSuplente.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    edtNomeVicePriSuplente.setBorder(null);
    edtNomeVicePriSuplente.setMaximumSize(new java.awt.Dimension(400, 30));
    edtNomeVicePriSuplente.setMinimumSize(new java.awt.Dimension(400, 30));
    edtNomeVicePriSuplente.setPreferredSize(new java.awt.Dimension(400, 30));
    jPanel17.add(edtNomeVicePriSuplente);

    jPanel19.setBackground(new java.awt.Color(0, 51, 51));
    jPanel19.setMaximumSize(new java.awt.Dimension(170, 30));
    jPanel19.setMinimumSize(new java.awt.Dimension(170, 30));
    jPanel19.setPreferredSize(new java.awt.Dimension(170, 30));

    javax.swing.GroupLayout jPanel19Layout = new javax.swing.GroupLayout(jPanel19);
    jPanel19.setLayout(jPanel19Layout);
    jPanel19Layout.setHorizontalGroup(
      jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 170, Short.MAX_VALUE)
    );
    jPanel19Layout.setVerticalGroup(
      jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 30, Short.MAX_VALUE)
    );

    jPanel17.add(jPanel19);

    btnFotoVice.setBackground(new java.awt.Color(0, 153, 204));
    btnFotoVice.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
    btnFotoVice.setForeground(new java.awt.Color(255, 255, 255));
    btnFotoVice.setText("Carregar Foto");
    btnFotoVice.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    btnFotoVice.setMaximumSize(new java.awt.Dimension(100, 29));
    btnFotoVice.setMinimumSize(new java.awt.Dimension(100, 29));
    btnFotoVice.setPreferredSize(new java.awt.Dimension(100, 29));
    btnFotoVice.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnFotoViceActionPerformed(evt);
      }
    });
    jPanel17.add(btnFotoVice);

    pnlNomeVicePriSuplente.add(jPanel17);

    jPanel18.setBackground(new java.awt.Color(0, 51, 51));
    jPanel18.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 2));
    pnlNomeVicePriSuplente.add(jPanel18);

    pnlVicePriSuplente.add(pnlNomeVicePriSuplente, java.awt.BorderLayout.CENTER);

    pnlFotoVicePriSuplente.setBackground(new java.awt.Color(0, 51, 51));
    pnlFotoVicePriSuplente.setMinimumSize(new java.awt.Dimension(100, 100));
    pnlFotoVicePriSuplente.setPreferredSize(new java.awt.Dimension(100, 100));
    pnlFotoVicePriSuplente.setLayout(new java.awt.CardLayout(2, 2));

    lblFotoVicePriSuplente.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
    pnlFotoVicePriSuplente.add(lblFotoVicePriSuplente, "card2");

    pnlVicePriSuplente.add(pnlFotoVicePriSuplente, java.awt.BorderLayout.EAST);

    pnlViceSuplente.add(pnlVicePriSuplente);

    pnlSegSuplente.setLayout(new java.awt.BorderLayout());

    jPanel9.setBackground(new java.awt.Color(0, 51, 51));
    jPanel9.setLayout(new java.awt.GridLayout(3, 0));

    jPanel13.setBackground(new java.awt.Color(0, 51, 51));
    jPanel13.setLayout(new java.awt.CardLayout());

    lblTextoSegSuplente.setBackground(new java.awt.Color(0, 51, 51));
    lblTextoSegSuplente.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    lblTextoSegSuplente.setForeground(new java.awt.Color(255, 255, 255));
    lblTextoSegSuplente.setText("Nome do Segundo Suplente");
    jPanel13.add(lblTextoSegSuplente, "card2");

    jPanel9.add(jPanel13);

    jPanel14.setBackground(new java.awt.Color(0, 51, 51));
    jPanel14.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

    edtNomeSegSuplente.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    edtNomeSegSuplente.setBorder(null);
    edtNomeSegSuplente.setMaximumSize(new java.awt.Dimension(400, 29));
    edtNomeSegSuplente.setMinimumSize(new java.awt.Dimension(400, 29));
    edtNomeSegSuplente.setPreferredSize(new java.awt.Dimension(400, 29));
    jPanel14.add(edtNomeSegSuplente);

    jPanel20.setBackground(new java.awt.Color(0, 51, 51));
    jPanel20.setMaximumSize(new java.awt.Dimension(170, 30));
    jPanel20.setMinimumSize(new java.awt.Dimension(170, 30));

    javax.swing.GroupLayout jPanel20Layout = new javax.swing.GroupLayout(jPanel20);
    jPanel20.setLayout(jPanel20Layout);
    jPanel20Layout.setHorizontalGroup(
      jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 170, Short.MAX_VALUE)
    );
    jPanel20Layout.setVerticalGroup(
      jPanel20Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 30, Short.MAX_VALUE)
    );

    jPanel14.add(jPanel20);

    btnFotoSegSuplente.setBackground(new java.awt.Color(0, 153, 204));
    btnFotoSegSuplente.setFont(new java.awt.Font("Segoe UI", 0, 12)); // NOI18N
    btnFotoSegSuplente.setForeground(new java.awt.Color(255, 255, 255));
    btnFotoSegSuplente.setText("Carregar Foto");
    btnFotoSegSuplente.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    btnFotoSegSuplente.setMaximumSize(new java.awt.Dimension(100, 29));
    btnFotoSegSuplente.setMinimumSize(new java.awt.Dimension(100, 29));
    btnFotoSegSuplente.setPreferredSize(new java.awt.Dimension(100, 29));
    btnFotoSegSuplente.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnFotoSegSuplenteActionPerformed(evt);
      }
    });
    jPanel14.add(btnFotoSegSuplente);

    jPanel9.add(jPanel14);

    jPanel15.setBackground(new java.awt.Color(0, 51, 51));
    jPanel15.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 2));
    jPanel9.add(jPanel15);

    pnlSegSuplente.add(jPanel9, java.awt.BorderLayout.CENTER);

    jPanel10.setBackground(new java.awt.Color(0, 51, 51));
    jPanel10.setPreferredSize(new java.awt.Dimension(100, 100));
    jPanel10.setLayout(new java.awt.CardLayout(2, 2));

    lblFotoSegSuplente.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
    jPanel10.add(lblFotoSegSuplente, "card2");

    pnlSegSuplente.add(jPanel10, java.awt.BorderLayout.EAST);

    pnlViceSuplente.add(pnlSegSuplente);

    jPanel2.add(pnlViceSuplente);

    jPanelCampos.add(jPanel2, java.awt.BorderLayout.CENTER);

    jPanel7.setBackground(new java.awt.Color(0, 51, 51));
    jPanel7.setMinimumSize(new java.awt.Dimension(10, 100));
    jPanel7.setPreferredSize(new java.awt.Dimension(10, 310));

    javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
    jPanel7.setLayout(jPanel7Layout);
    jPanel7Layout.setHorizontalGroup(
      jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 10, Short.MAX_VALUE)
    );
    jPanel7Layout.setVerticalGroup(
      jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 360, Short.MAX_VALUE)
    );

    jPanelCampos.add(jPanel7, java.awt.BorderLayout.EAST);

    jPanel8.setBackground(new java.awt.Color(0, 51, 51));
    jPanel8.setPreferredSize(new java.awt.Dimension(10, 310));

    javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
    jPanel8.setLayout(jPanel8Layout);
    jPanel8Layout.setHorizontalGroup(
      jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 10, Short.MAX_VALUE)
    );
    jPanel8Layout.setVerticalGroup(
      jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 360, Short.MAX_VALUE)
    );

    jPanelCampos.add(jPanel8, java.awt.BorderLayout.WEST);

    jPanelConsulta.setBackground(new java.awt.Color(0, 51, 51));

    jLabelFiltro.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jLabelFiltro.setForeground(new java.awt.Color(255, 255, 255));
    jLabelFiltro.setText("Filtro");

    jComboBoxListaFiltro.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jComboBoxListaFiltro.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nome" }));
    jComboBoxListaFiltro.setToolTipText("");
    jComboBoxListaFiltro.setBorder(null);

    jLabelValorPesquisa.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jLabelValorPesquisa.setForeground(new java.awt.Color(255, 255, 255));
    jLabelValorPesquisa.setText("Valor");

    jTextFieldInformacaoPesquisa.setFont(new java.awt.Font("Segoe UI", 0, 14)); // NOI18N
    jTextFieldInformacaoPesquisa.setText("teste");
    jTextFieldInformacaoPesquisa.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255), 4));
    jTextFieldInformacaoPesquisa.setMaximumSize(new java.awt.Dimension(400, 25));
    jTextFieldInformacaoPesquisa.setMinimumSize(new java.awt.Dimension(400, 25));
    jTextFieldInformacaoPesquisa.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jTextFieldInformacaoPesquisaActionPerformed(evt);
      }
    });
    jTextFieldInformacaoPesquisa.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jTextFieldInformacaoPesquisaKeyPressed(evt);
      }
    });

    javax.swing.GroupLayout jPanelConsultaLayout = new javax.swing.GroupLayout(jPanelConsulta);
    jPanelConsulta.setLayout(jPanelConsultaLayout);
    jPanelConsultaLayout.setHorizontalGroup(
      jPanelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanelConsultaLayout.createSequentialGroup()
        .addGap(25, 25, 25)
        .addGroup(jPanelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanelConsultaLayout.createSequentialGroup()
            .addComponent(jLabelValorPesquisa)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jTextFieldInformacaoPesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, 485, Short.MAX_VALUE))
          .addGroup(jPanelConsultaLayout.createSequentialGroup()
            .addComponent(jLabelFiltro)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jComboBoxListaFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addContainerGap(320, Short.MAX_VALUE))
    );
    jPanelConsultaLayout.setVerticalGroup(
      jPanelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanelConsultaLayout.createSequentialGroup()
        .addContainerGap()
        .addGroup(jPanelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabelFiltro)
          .addComponent(jComboBoxListaFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addGroup(jPanelConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabelValorPesquisa)
          .addComponent(jTextFieldInformacaoPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    jTextFieldInformacaoPesquisa.getAccessibleContext().setAccessibleName("");

    jFileChooser.setFileFilter(null);

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setMaximumSize(new java.awt.Dimension(800, 550));
    setMinimumSize(new java.awt.Dimension(800, 550));
    setPreferredSize(new java.awt.Dimension(800, 550));
    setResizable(false);

    jPanelBotoes.setBackground(new java.awt.Color(0, 51, 51));
    jPanelBotoes.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(255, 255, 255)));
    jPanelBotoes.setMaximumSize(new java.awt.Dimension(800, 50));
    jPanelBotoes.setMinimumSize(new java.awt.Dimension(800, 50));
    jPanelBotoes.setPreferredSize(new java.awt.Dimension(800, 50));
    jPanelBotoes.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 10, 10));

    jButtonConsultar.setBackground(new java.awt.Color(0, 153, 204));
    jButtonConsultar.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
    jButtonConsultar.setForeground(new java.awt.Color(255, 255, 255));
    jButtonConsultar.setText("Consultar");
    jButtonConsultar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    jButtonConsultar.setMaximumSize(new java.awt.Dimension(100, 30));
    jButtonConsultar.setMinimumSize(new java.awt.Dimension(100, 30));
    jButtonConsultar.setPreferredSize(new java.awt.Dimension(100, 30));
    jButtonConsultar.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        btnSetBackgroundMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        btnSetBackgrounMouseExited(evt);
      }
    });
    jButtonConsultar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonConsultarActionPerformed(evt);
      }
    });
    jPanelBotoes.add(jButtonConsultar);

    jButtonNovo.setBackground(new java.awt.Color(0, 153, 204));
    jButtonNovo.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
    jButtonNovo.setForeground(new java.awt.Color(255, 255, 255));
    jButtonNovo.setText("Novo");
    jButtonNovo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    jButtonNovo.setMaximumSize(new java.awt.Dimension(100, 30));
    jButtonNovo.setMinimumSize(new java.awt.Dimension(100, 30));
    jButtonNovo.setPreferredSize(new java.awt.Dimension(100, 30));
    jButtonNovo.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        btnSetBackgroundMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        btnSetBackgrounMouseExited(evt);
      }
    });
    jButtonNovo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonNovoActionPerformed(evt);
      }
    });
    jPanelBotoes.add(jButtonNovo);

    jButtonEditar.setBackground(new java.awt.Color(0, 153, 204));
    jButtonEditar.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
    jButtonEditar.setForeground(new java.awt.Color(255, 255, 255));
    jButtonEditar.setText("Editar");
    jButtonEditar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    jButtonEditar.setMaximumSize(new java.awt.Dimension(100, 30));
    jButtonEditar.setMinimumSize(new java.awt.Dimension(100, 30));
    jButtonEditar.setPreferredSize(new java.awt.Dimension(100, 30));
    jButtonEditar.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        btnSetBackgroundMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        btnSetBackgrounMouseExited(evt);
      }
    });
    jButtonEditar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonEditarActionPerformed(evt);
      }
    });
    jPanelBotoes.add(jButtonEditar);

    jButtonExcluir.setBackground(new java.awt.Color(0, 153, 204));
    jButtonExcluir.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
    jButtonExcluir.setForeground(new java.awt.Color(255, 255, 255));
    jButtonExcluir.setText("Excluir");
    jButtonExcluir.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    jButtonExcluir.setMaximumSize(new java.awt.Dimension(100, 30));
    jButtonExcluir.setMinimumSize(new java.awt.Dimension(100, 30));
    jButtonExcluir.setPreferredSize(new java.awt.Dimension(100, 30));
    jButtonExcluir.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        btnSetBackgroundMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        btnSetBackgrounMouseExited(evt);
      }
    });
    jButtonExcluir.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonExcluirActionPerformed(evt);
      }
    });
    jPanelBotoes.add(jButtonExcluir);

    jButtonGravar.setBackground(new java.awt.Color(0, 153, 204));
    jButtonGravar.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
    jButtonGravar.setForeground(new java.awt.Color(255, 255, 255));
    jButtonGravar.setText("Gravar");
    jButtonGravar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    jButtonGravar.setMaximumSize(new java.awt.Dimension(100, 30));
    jButtonGravar.setMinimumSize(new java.awt.Dimension(100, 30));
    jButtonGravar.setPreferredSize(new java.awt.Dimension(100, 30));
    jButtonGravar.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        btnSetBackgroundMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        btnSetBackgrounMouseExited(evt);
      }
    });
    jButtonGravar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonGravarActionPerformed(evt);
      }
    });
    jPanelBotoes.add(jButtonGravar);

    jButtonCancelar.setBackground(new java.awt.Color(0, 153, 204));
    jButtonCancelar.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
    jButtonCancelar.setForeground(new java.awt.Color(255, 255, 255));
    jButtonCancelar.setText("Cancelar");
    jButtonCancelar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 255)));
    jButtonCancelar.setMaximumSize(new java.awt.Dimension(100, 30));
    jButtonCancelar.setMinimumSize(new java.awt.Dimension(100, 30));
    jButtonCancelar.setPreferredSize(new java.awt.Dimension(100, 30));
    jButtonCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        btnSetBackgroundMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        btnSetBackgrounMouseExited(evt);
      }
    });
    jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButtonCancelarActionPerformed(evt);
      }
    });
    jPanelBotoes.add(jButtonCancelar);

    getContentPane().add(jPanelBotoes, java.awt.BorderLayout.NORTH);

    jPanelMeio.setBackground(new java.awt.Color(0, 51, 51));
    jPanelMeio.setMaximumSize(new java.awt.Dimension(800, 410));
    jPanelMeio.setMinimumSize(new java.awt.Dimension(800, 410));
    jPanelMeio.setPreferredSize(new java.awt.Dimension(800, 410));
    jPanelMeio.setRequestFocusEnabled(false);

    javax.swing.GroupLayout jPanelMeioLayout = new javax.swing.GroupLayout(jPanelMeio);
    jPanelMeio.setLayout(jPanelMeioLayout);
    jPanelMeioLayout.setHorizontalGroup(
      jPanelMeioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 800, Short.MAX_VALUE)
    );
    jPanelMeioLayout.setVerticalGroup(
      jPanelMeioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 410, Short.MAX_VALUE)
    );

    getContentPane().add(jPanelMeio, java.awt.BorderLayout.CENTER);

    jPanelStatus.setBackground(new java.awt.Color(0, 51, 51));
    jPanelStatus.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 0, 0, 0, new java.awt.Color(255, 255, 255)));
    jPanelStatus.setMaximumSize(new java.awt.Dimension(800, 30));
    jPanelStatus.setMinimumSize(new java.awt.Dimension(800, 30));
    jPanelStatus.setPreferredSize(new java.awt.Dimension(800, 30));
    jPanelStatus.setRequestFocusEnabled(false);
    jPanelStatus.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

    jLabelStatus.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N
    jLabelStatus.setForeground(new java.awt.Color(255, 51, 51));
    jLabelStatus.setText("sadfdsa");
    jLabelStatus.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    jLabelStatus.setMaximumSize(new java.awt.Dimension(200, 30));
    jLabelStatus.setMinimumSize(new java.awt.Dimension(30, 30));
    jLabelStatus.setPreferredSize(new java.awt.Dimension(100, 30));
    jPanelStatus.add(jLabelStatus);

    jLabelGravacao.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N
    jLabelGravacao.setForeground(new java.awt.Color(255, 255, 255));
    jLabelGravacao.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jLabelGravacao.setMaximumSize(new java.awt.Dimension(30, 30));
    jLabelGravacao.setMinimumSize(new java.awt.Dimension(30, 30));
    jLabelGravacao.setPreferredSize(new java.awt.Dimension(500, 30));
    jPanelStatus.add(jLabelGravacao);

    getContentPane().add(jPanelStatus, java.awt.BorderLayout.SOUTH);

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldInformacaoPesquisaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldInformacaoPesquisaKeyPressed

      if (evt.getKeyCode() == KeyEvent.VK_ENTER) {

        if (Candidato.consultar(jTextFieldInformacaoPesquisa.getText()) == null) {
          jLabelGravacao.setText("Candidato não existe");
        } else {
          ViewUtil.trocaPanels(jPanelMeio, jPanelCampos);
          EventoBotoes.consultando(jPanelBotoes.getComponents(), jPanelStatus.getComponents(), jPanelCampos.getParent().getComponents());
          candidatoModel = Candidato.consultar(jTextFieldInformacaoPesquisa.getText());
          jTextFieldNomeCandidato.setText(candidatoModel.getNome());
          jTextFieldNumeroCandidato.setText(String.format("%s", candidatoModel.getNumeroCandidato()));
          jTextFieldPartido.setText(candidatoModel.getPartido());
          jComboBoxCargos.setSelectedItem(candidatoModel.getCargo().getNome());
          edtNomeVicePriSuplente.setText(candidatoModel.getNomeVicePriSuplente());
          edtNomeSegSuplente.setText(candidatoModel.getNomeSegSuplente());
          loadFotoCandidato(candidatoModel.getEndFotoCandidato());
          loadFotoVicePriSuplente(candidatoModel.getEndFotoVicePriSuplente());
          loadFotoSegSuplente(candidatoModel.getEndFotoSegSuplente());
          ativaDesativaBotoes(false);
        }
      } else {
        jLabelGravacao.setText("");
      }
    }//GEN-LAST:event_jTextFieldInformacaoPesquisaKeyPressed

    private void jButtonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarActionPerformed
      EventoBotoes.inicio(jPanelBotoes.getComponents(), jPanelStatus.getComponents());
      ViewUtil.trocaPanels(jPanelMeio, jPanelConsulta);
      clearAllFields();
      ativaDesativaBotoes(false);
    }//GEN-LAST:event_jButtonConsultarActionPerformed

    private void jButtonNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNovoActionPerformed
      EventoBotoes.editando(jPanelBotoes.getComponents(), jPanelStatus.getComponents(), jPanelCampos.getComponents(), "N", true);
      ViewUtil.trocaPanels(jPanelMeio, jPanelCampos);
      clearAllFields();
      ativaDesativaBotoes(true);
    }//GEN-LAST:event_jButtonNovoActionPerformed

    private void jButtonEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditarActionPerformed
      EventoBotoes.editando(jPanelBotoes.getComponents(), jPanelStatus.getComponents(), jPanelCampos.getComponents(), "E", true);
      ativaDesativaBotoes(true);
    }//GEN-LAST:event_jButtonEditarActionPerformed

    private void jButtonExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExcluirActionPerformed
      Candidato.deletar(jTextFieldNomeCandidato.getText());
      EventoBotoes.inicio(jPanelBotoes.getComponents(), jPanelStatus.getComponents());
      ViewUtil.trocaPanels(jPanelMeio, jPanelConsulta);
      jLabelGravacao.setText("Registro excluído com sucesso !");
      clearAllFields();
      ativaDesativaBotoes(false);
    }//GEN-LAST:event_jButtonExcluirActionPerformed

    private void jButtonGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGravarActionPerformed
      Candidato cand = new Candidato();

      if (!isEmpty()) {
        if (!(Integer.parseInt(jTextFieldNumeroCandidato.getText()) < 0)) {
          if (jTextFieldNumeroCandidato.getText().length() == getQntdDigitosCargo()) {
            if (!(Candidato.existCandidato(jTextFieldNumeroCandidato.getText(), 
                 getCargoComboBox()) && (jLabelStatus.getText().equals("Inserindo")))) {

              cand.setNome(jTextFieldNomeCandidato.getText());
              cand.setPartido(jTextFieldPartido.getText());
              cand.setNumeroCandidato(Integer.parseInt(jTextFieldNumeroCandidato.getText()));
              cand.setCargo(getCargoComboBox());
              cand.setNomeVicePriSuplente(edtNomeVicePriSuplente.getText());
              cand.setNomeSegSuplente(edtNomeSegSuplente.getText());
              cand.setEndFotoCandidato(endFotoCandidato);
              cand.setEndFotoVicePriSuplente(endFotoVicePriSuplente);
              cand.setEndFotoSegSuplente(endFotoSegSuplente);

              switch (jLabelStatus.getText()) {
                case "Inserindo":
                  Candidato.inserir(cand);
                  break;
                case "Editando":
                  Candidato.editar(candidatoModel, cand);
                  break;
              }
              EventoBotoes.inicio(jPanelBotoes.getComponents(), jPanelStatus.getComponents());
              ViewUtil.trocaPanels(jPanelMeio, jPanelConsulta);
              clearAllFields();
            } else {
              jLabelGravacao.setText("Já existe um candidato cadastrado com esse número !");
              jTextFieldNumeroCandidato.requestFocus();
            }
          } else {
            jLabelGravacao.setText("A quantidade de dígitos incorreta para o Cargo selecionado !");
            jTextFieldNumeroCandidato.requestFocus();
          }
        } else {
          jLabelGravacao.setText("Número de cadidato incorreto !");
          jTextFieldNumeroCandidato.requestFocus();
        }
      } else {
        jLabelGravacao.setText("Preencha todos os campos !");
      }
    }//GEN-LAST:event_jButtonGravarActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
      if (UrnaUtil.confirmDialog("Deseja cancelar essa transação?", "Atenção")) {
        EventoBotoes.inicio(jPanelBotoes.getComponents(), jPanelStatus.getComponents());
        ViewUtil.trocaPanels(jPanelMeio, jPanelConsulta);
        clearAllFields();
      }
    }//GEN-LAST:event_jButtonCancelarActionPerformed

  private void jComboBoxCargosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxCargosActionPerformed
    clearFoto();
    Cargo cargoSelecionado = getCargoComboBox();

    if (cargoSelecionado != null) {
      setVisiblePanelDetalhe(true, (cargoSelecionado.isPossuiVice()), (cargoSelecionado.isPossuiSuplentes()));
    } else {
      setVisiblePanelDetalhe(false, false, false);
    }
  }//GEN-LAST:event_jComboBoxCargosActionPerformed

  private void btnFotoViceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFotoViceActionPerformed
    jFileChooser.showOpenDialog(this);
    loadFotoVicePriSuplente(jFileChooser.getSelectedFile().toString());
  }//GEN-LAST:event_btnFotoViceActionPerformed

  private void btnFotoSegSuplenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFotoSegSuplenteActionPerformed
    jFileChooser.showOpenDialog(this);
    loadFotoSegSuplente(jFileChooser.getSelectedFile().toString());
  }//GEN-LAST:event_btnFotoSegSuplenteActionPerformed

  private void btnFotoCandidatoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFotoCandidatoActionPerformed
    jFileChooser.showOpenDialog(this);
    loadFotoCandidato(jFileChooser.getSelectedFile().toString());
  }//GEN-LAST:event_btnFotoCandidatoActionPerformed

  private void btnSetBackgroundMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSetBackgroundMouseEntered
    /*if (evt.getComponent().isEnabled()) {
      evt.getComponent().setBackground(new Color(51, 51, 255));
    }*/
  }//GEN-LAST:event_btnSetBackgroundMouseEntered

  private void btnSetBackgrounMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSetBackgrounMouseExited
    /*if (evt.getComponent().isEnabled()) {
      evt.getComponent().setBackground(new Color(0, 153, 204));
    }*/
  }//GEN-LAST:event_btnSetBackgrounMouseExited

  private void jTextFieldInformacaoPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldInformacaoPesquisaActionPerformed
    // TODO add your handling code here:
  }//GEN-LAST:event_jTextFieldInformacaoPesquisaActionPerformed

  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        CadastroCandidato dialog = new CadastroCandidato(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
          @Override
          public void windowClosing(java.awt.event.WindowEvent e) {
            System.exit(0);
          }
        });
        dialog.setVisible(true);
      }
    });
  }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton btnFotoCandidato;
  private javax.swing.JButton btnFotoSegSuplente;
  private javax.swing.JButton btnFotoVice;
  private javax.swing.JTextField edtNomeSegSuplente;
  private javax.swing.JTextField edtNomeVicePriSuplente;
  private javax.swing.JButton jButtonCancelar;
  private javax.swing.JButton jButtonConsultar;
  private javax.swing.JButton jButtonEditar;
  private javax.swing.JButton jButtonExcluir;
  private javax.swing.JButton jButtonGravar;
  private javax.swing.JButton jButtonNovo;
  private javax.swing.JComboBox jComboBoxCargos;
  private javax.swing.JComboBox jComboBoxListaFiltro;
  private javax.swing.JFileChooser jFileChooser;
  private javax.swing.JLabel jLabelCargo;
  private javax.swing.JLabel jLabelFiltro;
  private javax.swing.JLabel jLabelGravacao;
  private javax.swing.JLabel jLabelNomeCandidato;
  private javax.swing.JLabel jLabelNumeroCandidato;
  private javax.swing.JLabel jLabelPartido;
  private javax.swing.JLabel jLabelStatus;
  private javax.swing.JLabel jLabelValorPesquisa;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel10;
  private javax.swing.JPanel jPanel11;
  private javax.swing.JPanel jPanel12;
  private javax.swing.JPanel jPanel13;
  private javax.swing.JPanel jPanel14;
  private javax.swing.JPanel jPanel15;
  private javax.swing.JPanel jPanel16;
  private javax.swing.JPanel jPanel17;
  private javax.swing.JPanel jPanel18;
  private javax.swing.JPanel jPanel19;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JPanel jPanel20;
  private javax.swing.JPanel jPanel3;
  private javax.swing.JPanel jPanel4;
  private javax.swing.JPanel jPanel5;
  private javax.swing.JPanel jPanel6;
  private javax.swing.JPanel jPanel7;
  private javax.swing.JPanel jPanel8;
  private javax.swing.JPanel jPanel9;
  private javax.swing.JPanel jPanelBotoes;
  private javax.swing.JPanel jPanelCampos;
  private javax.swing.JPanel jPanelConsulta;
  private javax.swing.JPanel jPanelMeio;
  private javax.swing.JPanel jPanelStatus;
  private javax.swing.JTextField jTextFieldInformacaoPesquisa;
  private javax.swing.JTextField jTextFieldNomeCandidato;
  private javax.swing.JTextField jTextFieldNumeroCandidato;
  private javax.swing.JTextField jTextFieldPartido;
  private javax.swing.JLabel lblFotoCandidato;
  private javax.swing.JLabel lblFotoSegSuplente;
  private javax.swing.JLabel lblFotoVicePriSuplente;
  private javax.swing.JLabel lblTextoSegSuplente;
  private javax.swing.JLabel lblTextoVicePriSuplente;
  private javax.swing.JPanel pnlFotoVicePriSuplente;
  private javax.swing.JPanel pnlNomeVicePriSuplente;
  private javax.swing.JPanel pnlSegSuplente;
  private javax.swing.JPanel pnlVicePriSuplente;
  private javax.swing.JPanel pnlViceSuplente;
  // End of variables declaration//GEN-END:variables

  private void carregarComboBoxCargo() {
    for (Cargo listaCargos : cargos) {
      jComboBoxCargos.addItem(listaCargos.getNome());
    }

  }

  private int getQntdDigitosCargo() {
    for (Cargo cargo : cargos) {
      if (jComboBoxCargos.getSelectedItem().toString().equals(cargo.getNome())) {
        return cargo.getQntdDigitos();
      }
    }
    return 0;
  }

  private void clearAllFields() {
    clearFoto();
    jTextFieldInformacaoPesquisa.setText("");
    jTextFieldNomeCandidato.setText("");
    edtNomeVicePriSuplente.setText("");
    edtNomeSegSuplente.setText("");
    jTextFieldNumeroCandidato.setText("");
    jTextFieldPartido.setText("");
  }

  private void clearFoto() {
    loadFotoCandidato("/img/img00.jpg");
    loadFotoVicePriSuplente("/img/img00.jpg");
    loadFotoSegSuplente("/img/img00.jpg");
  }

  private void loadFotoCandidato(String endereco) {
    endFotoCandidato = endereco;
    ViewUtil.loadFoto(lblFotoCandidato, endFotoCandidato);
  }

  private void loadFotoVicePriSuplente(String endereco) {
    endFotoVicePriSuplente = endereco;
    ViewUtil.loadFoto(lblFotoVicePriSuplente, endFotoVicePriSuplente);
  }

  private void loadFotoSegSuplente(String endereco) {
    endFotoSegSuplente = endereco;
    ViewUtil.loadFoto(lblFotoSegSuplente, endFotoSegSuplente);
  }

  private boolean isEmpty() {

    boolean result = false;
    Cargo cargoSelecionado = getCargoComboBox();

    if (jTextFieldNomeCandidato.getText().isEmpty()) {
      jTextFieldNomeCandidato.requestFocus();
      result = true;
    }
    if (jTextFieldPartido.getText().isEmpty()) {
      jTextFieldPartido.requestFocus();
      result = true;
    }
    if (jTextFieldNumeroCandidato.getText().isEmpty()) {
      jTextFieldNumeroCandidato.requestFocus();
      result = true;
    }
    if (cargoSelecionado.isPossuiVice()) {
      if (edtNomeVicePriSuplente.getText().isEmpty()) {
        edtNomeVicePriSuplente.requestFocus();
        result = true;
      }
    } else if (cargoSelecionado.isPossuiSuplentes()) {
      if (edtNomeVicePriSuplente.getText().isEmpty()) {
        edtNomeVicePriSuplente.requestFocus();
        result = true;
      }
      if (edtNomeSegSuplente.getText().isEmpty()) {
        edtNomeSegSuplente.requestFocus();
        result = true;
      }
    }
    if (jComboBoxCargos.getSelectedIndex() == -1) {
      jComboBoxCargos.requestFocus();
      result = true;
    }
    return result;
  }

  private void setVisiblePanelDetalhe(boolean detalheCandidato, boolean detalheVice, boolean detalheSuplente) {
    jPanel2.setVisible(detalheCandidato);

    if (detalheVice) {
      lblTextoVicePriSuplente.setText("Nome do Vice");
    }

    if (detalheSuplente) {
      lblTextoVicePriSuplente.setText("Nome do Primeiro Suplente");
    }
    pnlSegSuplente.setVisible(detalheSuplente && !detalheVice);
    pnlViceSuplente.setVisible(detalheVice || detalheSuplente);
    pnlVicePriSuplente.setVisible(detalheVice || detalheSuplente);
  }

  private Cargo getCargoComboBox() {
    return Cargo.consultar(jComboBoxCargos.getSelectedItem().toString());
  }
  
  private void ativaDesativaBotoes(boolean habilita) {
    btnFotoCandidato.setEnabled(habilita);
    btnFotoVice.setEnabled(habilita);
    btnFotoSegSuplente.setEnabled(habilita);
  }
}
